var token = localStorage.getItem("token"),
    personalInformation = Sendajax("http://119.23.46.241:8080/login/personalpage/selpersonalinfo", "post", "", token)
if (localStorage.getItem("Refresh") == 1) {
    localStorage.setItem("Refresh", 0)
    history.go(0)
}

showData(personalInformation.data)

function showData(data) {
    if (data.headImg) {
        $(".head-portrait-image").html(`<img src="${data.headImg}" alt="">`)
    } else {
        $(".head-portrait-image").html(`<p>${data.name.substr(-2)}</p>`)
    }
    $(".username").text(data.username)
    $(".basic-information").attr("data-uId", data.id)
}

$(".updata-head-portrait-image").on("change", function () {
    if ($(this).val()) {
        let file = this.files[0],
            reader = new FileReader()
        $(reader).on("load", function (e) {
            let updateHeaderForm = new FormData()
            updateHeaderForm.append('header', file)
            let updateHeader = SendFileajax("http://119.23.46.241:8080/login/personalpage/updateheader", "post", updateHeaderForm, token)

            if (updateHeader.code == 201) {
                $(".head-portrait-image").html(`<img src="${e.target.result}" alt="">`)

                $("#footer").after(`<section class="tips">
              <section>
              <section class="exit-header"><p>头像修改成功</p></section>
               <section class="exit-footer">
             <button>确定</button>
                </section>
           </section>
                </section>`)
                stop()
                $(".exit-footer button:nth-child(1)").on("click", function () {
                    $(".tips").remove()
                    move()
                })
            }
        })
        reader.readAsDataURL(file)
    }
})
